<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
        <title>Shell编程基础03 - 德国粗茶淡饭</title><meta name="Description" content="Shell编程基础03"><meta property="og:title" content="Shell编程基础03" />
<meta property="og:description" content="Shell编程基础03" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://www.ctq6.cn/technology/linux/shell%E7%BC%96%E7%A8%8B%E5%9F%BA%E7%A1%8003/" />
<meta property="og:image" content="https://www.ctq6.cn/logo.png"/>
<meta property="article:published_time" content="2021-02-16T19:09:34+08:00" />
<meta property="article:modified_time" content="2021-02-16T19:09:34+08:00" />
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="https://www.ctq6.cn/logo.png"/>

<meta name="twitter:title" content="Shell编程基础03"/>
<meta name="twitter:description" content="Shell编程基础03"/>
<meta name="application-name" content="LoveIt">
<meta name="apple-mobile-web-app-title" content="LoveIt"><meta name="theme-color" content="#ffffff"><meta name="msapplication-TileColor" content="#da532c"><link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
        <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
        <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5"><link rel="manifest" href="/site.webmanifest"><link rel="canonical" href="https://www.ctq6.cn/technology/linux/shell%E7%BC%96%E7%A8%8B%E5%9F%BA%E7%A1%8003/" /><link rel="prev" href="https://www.ctq6.cn/technology/linux/shell%E7%BC%96%E7%A8%8B%E5%9F%BA%E7%A1%8001/" /><link rel="next" href="https://www.ctq6.cn/technology/linux/ssl%E8%AF%81%E4%B9%A6%E8%87%AA%E5%8A%A8%E7%BB%AD%E7%AD%BE/" /><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/normalize.css@8.0.1/normalize.min.css"><link rel="stylesheet" href="/css/style.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.13.0/css/all.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.7.2/animate.min.css"><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "Shell编程基础03",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "https:\/\/www.ctq6.cn\/technology\/linux\/shell%E7%BC%96%E7%A8%8B%E5%9F%BA%E7%A1%8003\/"
        },"image": [{
                            "@type": "ImageObject",
                            "url": "https:\/\/www.ctq6.cn\/images\/Apple-Devices-Preview.png",
                            "width":  3200 ,
                            "height":  2048 
                        }],"genre": "technology","keywords": "Linux","wordcount":  1981 ,
        "url": "https:\/\/www.ctq6.cn\/technology\/linux\/shell%E7%BC%96%E7%A8%8B%E5%9F%BA%E7%A1%8003\/","datePublished": "2021-02-16T19:09:34+08:00","dateModified": "2021-02-16T19:09:34+08:00","license": "This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.","publisher": {
            "@type": "Organization",
            "name": "xxxx","logo": {
                    "@type": "ImageObject",
                    "url": "https:\/\/www.ctq6.cn\/images\/avatar.png",
                    "width":  528 ,
                    "height":  560 
                }},"author": {
                "@type": "Person",
                "name": "MikelPan"
            },"description": "Shell编程基础03"
    }
    </script></head>
    <body header-desktop="fixed" header-mobile="auto"><script type="text/javascript">(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('auto' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : 'auto' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/" title="德国粗茶淡饭"><span class="header-title-pre"><i class='far fa-kiss-wink-heart fa-fw'></i></span>德国粗茶淡饭</a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/posts/"> 生活 </a><a class="menu-item" href="/technology/"> 技术 </a><a class="menu-item" href="/tags/"> 标签 </a><a class="menu-item" href="/categories/"> 分类 </a><a class="menu-item" href="/categories/documentation/"> 文档 </a><a class="menu-item" href="/about/"> 关于 </a><a class="menu-item" href="https://github.com/MikelPan/Cnblog.git" title="GitHub" rel="noopener noreffer" target="_blank"><i class='fab fa-github fa-fw'></i>  </a><span class="menu-item delimiter"></span><a href="javascript:void(0);" class="menu-item language" title="选择语言">简体中文<i class="fas fa-chevron-right fa-fw"></i>
                        <select class="language-select" id="language-select-desktop" onchange="location = this.value;"><option value="/technology/linux/shell%E7%BC%96%E7%A8%8B%E5%9F%BA%E7%A1%8003/" selected>简体中文</option></select>
                    </a><span class="menu-item search" id="search-desktop">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-desktop">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-desktop" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-desktop" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-desktop">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </span><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/" title="德国粗茶淡饭"><span class="header-title-pre"><i class='far fa-kiss-wink-heart fa-fw'></i></span>德国粗茶淡饭</a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><div class="search-wrapper">
                    <div class="search mobile" id="search-mobile">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-mobile">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-mobile" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-mobile" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-mobile">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </div>
                    <a href="javascript:void(0);" class="search-cancel" id="search-cancel-mobile">
                        取消
                    </a>
                </div><a class="menu-item" href="/posts/" title="">生活</a><a class="menu-item" href="/technology/" title="">技术</a><a class="menu-item" href="/tags/" title="">标签</a><a class="menu-item" href="/categories/" title="">分类</a><a class="menu-item" href="/categories/documentation/" title="">文档</a><a class="menu-item" href="/about/" title="">关于</a><a class="menu-item" href="https://github.com/MikelPan/Cnblog.git" title="GitHub" rel="noopener noreffer" target="_blank"><i class='fab fa-github fa-fw'></i></a><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                <i class="fas fa-adjust fa-fw"></i>
            </a><a href="javascript:void(0);" class="menu-item" title="选择语言">简体中文<i class="fas fa-chevron-right fa-fw"></i>
                    <select class="language-select" onchange="location = this.value;"><option value="/technology/linux/shell%E7%BC%96%E7%A8%8B%E5%9F%BA%E7%A1%8003/" selected>简体中文</option></select>
                </a></div>
    </div>
</header>
<div class="search-dropdown desktop">
    <div id="search-dropdown-desktop"></div>
</div>
<div class="search-dropdown mobile">
    <div id="search-dropdown-mobile"></div>
</div>
<main class="main">
                <div class="container"><div class="page single special"><h1 class="single-title animated pulse faster">Shell编程基础03</h1><div class="content" id="content"><h2 id="for循环语句">for循环语句</h2>
<p>在计算机科学中，for循环（英语：for loop）是一种编程语言的迭代陈述，能够让程式码反复的执行。它跟其他的循环，如while循环，最大的不同，是它拥有一个循环计数器，或是循环变数。这使得for循环能够知道在迭代过程中的执行顺序。</p>
<h3 id="shell中的for循环">shell中的for循环</h3>
<p>shell中的for 循环与在c中不同，它包含三种形式：
第一种结构是列表for 循环;
第二种结构就是不带列表的for循环；
第三种就类似于C语言。</p>
<p>1、列表for循环(常用)</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1">#！/bin/bash</span>
<span class="k">for</span> i in 取值列表
<span class="k">do</span>
    循环主体/命令
<span class="k">done</span>
</code></pre></td></tr></table>
</div>
</div><p>2、不带列表for循环(示例)</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="cp">#!/bin/absh
</span><span class="cp"></span><span class="nb">echo</span> <span class="s2">&#34;今天是什么日子：&#34;</span>  
<span class="k">for</span> i 
     <span class="k">do</span>   
     <span class="nb">echo</span> <span class="s2">&#34;</span><span class="nv">$i</span><span class="s2">&#34;</span> 
<span class="k">done</span> 
</code></pre></td></tr></table>
</div>
</div><p>脚本执行结果：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="o">[</span>root@kube-master ~<span class="o">]</span><span class="c1"># sh test.sh 好日子</span>
今天是什么日子：
好日子
</code></pre></td></tr></table>
</div>
</div><p>3、类似C语言的风格（这种用法常在C语语言中使用）</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="k">for</span><span class="o">((</span><span class="nv">i</span><span class="o">=</span>0<span class="p">;</span>i&lt;<span class="o">=</span>3<span class="p">;</span>i++<span class="o">))</span>
    <span class="k">do</span>
      <span class="nb">echo</span> <span class="nv">$i</span>
<span class="k">done</span> 
</code></pre></td></tr></table>
</div>
</div><h2 id="while循环语句">while循环语句</h2>
<p>在编程语言中，while循环（英语：while loop）是一种控制流程的陈述。利用一个返回结果为布林值（Boolean）的表达式作为循环条件，当这个表达式的返回值为“真”（true）时，则反复执行循环体内的程式码；若表达式的返回值为“假”（false），则不再执行循环体内的代码，继续执行循环体下面的代码。</p>
<p>因为while循环在区块内代码被执行之前，先检查陈述是否成立，因此这种控制流程通常被称为是一种前测试循环（pre-test loop）。相对而言do while循环，是在循环区块执行结束之后，再去检查陈述是否成立，被称为是后测试循环。</p>
<h3 id="shell中while语法">shell中while语法</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="k">while</span> 条件
  <span class="k">do</span>
    命令
<span class="k">done</span>
</code></pre></td></tr></table>
</div>
</div><p>sleep 单位 秒  sleep 1 休息1秒
usleep 单位 微秒 usleep 1000000 休息1s
1微秒等于百万分之一秒（10的负6次方秒）</p>
<h2 id="break-continue-exit-return">break continue exit return</h2>
<p>条件与循环控制及程序返回值命令表</p>
<table>
<thead>
<tr>
<th style="text-align:left">命令</th>
<th style="text-align:left">说明　</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">break n</td>
<td style="text-align:left">如果省略n，则表示跳出整个循环，n表示跳出循环的层数</td>
</tr>
<tr>
<td style="text-align:left">continue n</td>
<td style="text-align:left">如果省略n，则表示跳过本次循环，忽略本次循环的剩余代码，进人循环的下一次循环。 n表示退到第n层继续循环</td>
</tr>
<tr>
<td style="text-align:left">exit n</td>
<td style="text-align:left">退出当前Shell程序，n为上一次程序执行的状态返回值。n也可以省略，在下一个Shell里可通过&quot;$?&ldquo;接收exit n的n值</td>
</tr>
<tr>
<td style="text-align:left">return n</td>
<td style="text-align:left">用于在函数里作为函数的返回值，以判断函数执行是否正确。在下一个Shell里可通过&rdquo;$?&ldquo;接收exit n的n值</td>
</tr>
</tbody>
</table>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">简单来说即：
<span class="nb">break</span>    跳出循环
<span class="k">continue</span> 跳出本次循环
<span class="nb">exit</span>     退出脚本
<span class="k">return</span>   与 <span class="nb">exit</span> 相同，在函数中使用
</code></pre></td></tr></table>
</div>
</div><h3 id="break命令说明">break命令说明</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span><span class="lnt">9
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="o">[</span>root@k8s-master<span class="o">]</span> <span class="c1"># help break </span>
break: <span class="nb">break</span> <span class="o">[</span>n<span class="o">]</span>
    退出 <span class="k">for</span>、while、或 <span class="k">until</span> 循环
    
    退出一个 FOR、WHILE 或 UNTIL 循环。如果指定了N，则打破N重
    循环
    
    退出状态：
    退出状态为0除非 N 不大于或等于 1。
</code></pre></td></tr></table>
</div>
</div><h3 id="continue命令说明">continue命令说明</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span><span class="lnt">9
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="o">[</span>root@k8s-master<span class="o">]</span><span class="c1"># help continue </span>
<span class="k">continue</span>: <span class="k">continue</span> <span class="o">[</span>n<span class="o">]</span>
    继续 <span class="k">for</span>、while、或 <span class="k">until</span> 循环。
    
    继续当前 FOR、WHILE 或 UNTIL 循环的下一步。
    如果指定了 N， 则继续当前的第 N 重循环。
    
    退出状态：
    退出状态为 <span class="m">0</span> 除非 N 不大于或等于1。
</code></pre></td></tr></table>
</div>
</div><h3 id="exit命令说明">exit命令说明</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="o">[</span>root@k8s-master<span class="o">]</span><span class="c1"># help exit</span>
exit: <span class="nb">exit</span> <span class="o">[</span>n<span class="o">]</span>
    退出shell。
    
    以状态 N 退出 shell。  如果 N 被省略，则退出状态
    为最后一个执行的命令的退出状态。
</code></pre></td></tr></table>
</div>
</div><h3 id="return命令说明">return命令说明</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="o">[</span>root@k8s-master<span class="o">]</span><span class="c1"># help return </span>
<span class="k">return</span>: <span class="k">return</span> <span class="o">[</span>n<span class="o">]</span>
    从一个 shell 函数返回。
    
    使一个函数或者被引用的脚本以指定的返回值 N 退出。
    如果 N 被省略，则返回状态就是
    函数或脚本中的最后一个执行的命令的状态。
    
    退出状态：
    返回 N，或者如果 shell 不在执行一个函数或引用脚本时，失败。
</code></pre></td></tr></table>
</div>
</div><h2 id="shell中的数组">shell中的数组</h2>
<h3 id="为什么会产生shell数组">为什么会产生Shell数组</h3>
<p>通常在开发Shell脚本时，定义变量采用的形式为“a=l;b=2;C=3”，可如果有多个 变量呢？这时再逐个地定义就会很费劲，并且要是有多个不确定的变量内容，也会难以 进行变量定义，此外，快速读取不同变量的值也是一件很痛苦的事情，于是数组就诞生 了，它就是为了解决上述问题而出现的。</p>
<h3 id="什么是shell数组">什么是Shell数组</h3>
<p>Shell的数组就是一个元素集合，它把有限个元素（变量或字符内容）用一个名字来 命名，然后用编号对它们进行区分。这个名字就称为数组名，用于区分不同内容的编 号就称为数组下标。组成数组的各个元素（变量）称为数组的元素，有时也称为下标变量.</p>
<h3 id="数组中的增删改查">数组中的增删改查</h3>
<p>Shell的数组就是一个元素集合，它把有限个元素（变量或字符内容）用一个名字来 命名，然后用编号对它们进行区分。这个名字就称为数组名，用于区分不同内容的编 号就称为数组下标。组成数组的各个元素（变量）称为数组的元素，有时也称为下标变量.</p>
<p><em>shell数组的定义</em></p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 使用小括号将变量括起来赋值</span>
<span class="nv">array</span><span class="o">=(</span><span class="m">1</span> <span class="m">2</span> 3<span class="o">)</span>
<span class="nb">echo</span> <span class="si">${</span><span class="nv">array</span><span class="p">[*]</span><span class="si">}</span>
<span class="m">1</span> <span class="m">2</span> <span class="m">3</span>
<span class="c1"># 使用小括号将变量括起来赋值,同时采用键值对的方式赋值</span>
<span class="nv">array</span><span class="o">=([</span>1<span class="o">]=</span>one <span class="o">[</span>2<span class="o">]=</span>two <span class="o">[</span>3<span class="o">]=</span>three<span class="o">)</span>
<span class="nb">echo</span> <span class="si">${</span><span class="nv">array</span><span class="p">[*]</span><span class="si">}</span>
one two three
</code></pre></td></tr></table>
</div>
</div><p><em>数组增加与修改</em></p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 通过添加下标的方式增加数组</span>
array<span class="o">[</span>4<span class="o">]=</span>four
array<span class="o">[</span>3<span class="o">]=</span>five
<span class="nb">echo</span> <span class="si">${</span><span class="nv">array</span><span class="p">[*]</span><span class="si">}</span>
one two five four
</code></pre></td></tr></table>
</div>
</div><p><em>数组的删除</em></p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 通过unset[]下标删除</span>
<span class="nb">unset</span> array<span class="o">[</span>1<span class="o">]</span>
ehco <span class="si">${</span><span class="nv">array</span><span class="p">[*]</span><span class="si">}</span>
two three
</code></pre></td></tr></table>
</div>
</div><h2 id="shell-函数">shell 函数</h2>
<h3 id="shell-函数语法">shell 函数语法</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"><span class="c1"># 第一种写法</span>
<span class="k">function</span> main<span class="o">()</span> <span class="o">{</span>
    函数体
    <span class="k">return</span> n
<span class="o">}</span>
<span class="c1"># 第二种写法</span>
main <span class="o">()</span> <span class="o">{</span>
    函数体
    <span class="k">return</span> n
<span class="o">}</span>
</code></pre></td></tr></table>
</div>
</div></div><div id="comments"></div></div></div>
            </main><footer class="footer">
        <div class="footer-container"><div class="footer-line"><i class="far fa-copyright fa-fw"></i><span itemprop="copyrightYear">2019 - 2021</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="/" target="_blank">mikel pan</a></span>&nbsp;|&nbsp;<span class="license"><a rel="license external nofollow noopener noreffer" href="https://creativecommons.org/licenses/by-nc/4.0/" target="_blank">CC BY-NC 4.0</a></span><span class="icp-splitter">&nbsp;|&nbsp;</span><br class="icp-br"/>
                    <span class="icp"><a href="https://beian.miit.gov.cn/" target="_blank">粤ICP备2021047442号</a></span></div>
        </div>
    </footer></div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-arrow-up fa-fw"></i>
            </a><a href="#" id="view-comments" class="fixed-button" title="查看评论">
                <i class="fas fa-comment fa-fw"></i>
            </a>
        </div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/lightgallery.js@1.2.0/dist/css/lightgallery.min.css"><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/smooth-scroll@16.1.3/dist/smooth-scroll.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/autocomplete.js@0.37.1/dist/autocomplete.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/algoliasearch@4.2.0/dist/algoliasearch-lite.umd.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lazysizes@5.2.2/lazysizes.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lightgallery.js@1.2.0/dist/js/lightgallery.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lg-thumbnail.js@1.2.0/dist/lg-thumbnail.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lg-zoom.js@1.2.0/dist/lg-zoom.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/clipboard@2.0.6/dist/clipboard.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/sharer.js@0.4.0/sharer.min.js"></script><script type="text/javascript">window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":10},"comment":{},"lightGallery":{"actualSize":false,"exThumbImage":"data-thumbnail","hideBarsDelay":2000,"selector":".lightgallery","speed":400,"thumbContHeight":80,"thumbWidth":80,"thumbnail":true},"search":{"algoliaAppID":"REQJX89W85","algoliaIndex":"index.zh-cn","algoliaSearchKey":"63fa048de9b35627f46672e95abc14df","highlightTag":"em","maxResultLength":10,"noResultsFound":"没有找到结果","snippetLength":50,"type":"algolia"}};</script><script type="text/javascript" src="/js/theme.min.js"></script></body>
</html>
